package com.acmedcare.framework.spring.cloud.nacos.app;

import com.acmedcare.framework.boot.snowflake.EnableSnowflake;
import com.acmedcare.framework.exchange.center.endpoint.ExchangeCenterServer;
import com.acmedcare.framework.exchange.center.entity.bean.Task;
import com.acmedcare.framework.exchange.center.entity.dto.CommandEvent;
import com.acmedcare.framework.starter.bus.jackson.AcmedcareEventScan;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import xyz.vopen.tiffany.swagger.EnableSwagger2;

/**
 * {@link ApplicationCloudBootstrap}
 *
 * @author <a href="mailto:iskp.me@gmail.com">stefan.gu</a>
 * @version ${project.version} - 2019-09-02.
 */
@EnableSwagger2
@SpringBootApplication(scanBasePackageClasses = {ExchangeCenterServer.class})
@EnableDiscoveryClient
@AcmedcareEventScan(basePackageClasses = {CommandEvent.class, Task.class})
@EnableSnowflake(workerId = "10")
@Slf4j
public class ApplicationCloudBootstrap extends ExchangeCenterServer {

  public static void main(String[] args) throws IOException {
    // new application
    try {

      ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder()
          .sources(ApplicationCloudBootstrap.class)

          // default properties
          .properties("--spring.profiles.active=default,production")
          .web(WebApplicationType.SERVLET)
          .run(args);
    } catch (Exception e) {
      log.error("启动 spring boot 异常:" + e.getMessage(), e);
    }
    // GrpcLauncher.startControl(applicationContext);
  }
}
